package com.adingxiong.cft.design.servicelocation;

/**
 * @ClassName ServiceLocator
 * @Description TODO
 * @Author xiongchao
 * @Date 2021/1/8 9:36
 **/
public class ServiceLocator {

    public static Cache cache;

    static {
        cache = new Cache();
    }

    public static Service getService(String jndName) {
        Service service = cache.getService(jndName);
        if(service != null) {
            return service;
        }
        InitContext initContext = new InitContext();
        Service lookup = (Service) initContext.lookup(jndName);
        cache.addService(lookup);
        return lookup;

    }
}
